﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Threading.Tasks;

using Coder.ViewModel;
using Coder.Framework;

namespace Coder
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    /// 
    public sealed partial class MainPage : Page
    {
        GlobalViewModel GlobalViewModel;

        public MainPage(GlobalViewModel globalViewModel)
        {
            GlobalViewModel = globalViewModel;
            this.InitializeComponent();
            BindAll();

        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        /// <summary>
        /// Binds the Global Static ViewModel to the MainPage.xaml
        /// </summary>
        public void BindAll()
        {
            //Set up the Mini Challenge List Positions.
            App.GlobalViewModel.ChallengeViewModel.GeneratePositionChallenges(400, 175, 3, 8);
            MiniChallengeViewModel.DataContext = App.GlobalViewModel.ChallengeViewModel;
        }

        private void ChallengeSelected(object sender, SelectionChangedEventArgs e)
        {

            Window.Current.Content = new Pages.Editor(GlobalViewModel, new Project(GlobalViewModel.ChallengeViewModel.ChallengeList[(sender as VariableGridView).SelectedIndex], 27)); //2 is a dummy language ID.
        }
    }
}
